//N皇后

class Solution {
public: 
    vector<bool> col;
    vector<bool> k1;
    vector<bool> k2;
    vector<vector<string>> ret;
    vector<string> path;
    vector<vector<string>> solveNQueens(int n) {
        col.resize(n);
        k1.resize(2 * n);
        k2.resize(2 * n);
        path.resize(n);
        for(int i = 0; i < n; i++)
        {
            path[i].append(n, '.');
        }
        dfs(n, 0);
        return ret;
    }
    void dfs(int n, int pos)
    {
        if(pos == n)
        {
            ret.push_back(path);
            return;
        }
        for(int i = 0; i < n; i++)
        {
            if(!col[i] && !k1[pos - i + n] && !k2[pos + i])
            {
                path[pos][i] = 'Q';
                col[i] = true;
                k1[pos - i + n] = true;
                k2[i + pos] = true;
                dfs(n, pos + 1);
                path[pos][i] = '.';
                col[i] = false;
                k1[pos - i + n] = false;
                k2[i + pos] = false;
            }
        }
    }
};